{{ template "header.html" }}

<div class="item">
    WebToolsGo--静态资源文件列表
</div>
<div class="item">
    <button onclick="indexDir()" style="height: 30px">根目录</button>
    <button onclick="preDir()" style="height: 30px">上一级</button>
</div>
<div class="item" id="file-list">
    <div id="file-list-c"></div>
</div>

<script>
    var prePath = "/"

    // 获取初始文件列表
    $(function () {
        moreFileList("/")
    })

    function moreFileList(path) {
        $.post("/file-list", {path: path}, function (res) {
            let files = res.msg
            let data = "<div id=\"file-list-c\">"
            for (let i = 0; i < files.length; i++) {
                if (files[i].ext === "dir") {
                    data += "<p style='color: #f39e6f; cursor: pointer' onclick=moreFileList('"+ files[i].path +"')>" + files[i].name + "</p>"
                } else {
                    data += "<a target='_blank' href='/assets"+ files[i].path +"'>" + files[i].name + "</a> <br>"
                }
            }
            data += "</div>"
            $("#file-list-c").remove()
            $("#file-list").append(data)
            prePath = res.prePath
        }, "json")
    }

    // 首页
    function indexDir() {
        moreFileList("/")
    }

    // 返回上一级
    function preDir() {
        moreFileList(prePath)
    }
</script>

{{ template "footer.html" }}